#include <iostream>
#include <conio.h>
#include "Console.h"
#include "TicTacToe.h"

using namespace std;
using namespace Course;



TicTacToe::TicTacToe(void)
{
}



TicTacToe::~TicTacToe(void)
{
}



void TicTacToe::Draw()
{
	int x, y;
	for(x=8; x<27; x++)
	{
		for(y=2; y<21; y++)
		{
			Console::gotoxy(x,y);
			if(y==2 || y==8 || y==14 || y==20)
				cout<<"-";
			else
				if(x==8 || x==14 || x==20 || x==26)
					cout<<"!";
		}
		y=10;
	}
}



void TicTacToe::Play()
{
	Console::gotoxy(17, 11);
	int p_code=0;
	int KB_code = 0;
	
	while(1)
	{
		if(_kbhit())
		{
			KB_code = _getch();
		
				switch(_getch()){
					case 72 : // Upp
						if(Console::wherey() > 5)
							Console::gotoxy(Console::wherex(), Console::wherey() -6);
						break;

					case 80 : 
						if(Console::wherey() < 17)
							Console::gotoxy(Console::wherex(), Console::wherey() +6);
						break;

					case 75 :
						if(Console::wherex() > 11)
							Console::gotoxy(Console::wherex() -6, Console::wherey());
						break;

					case 77 :
						if(Console::wherex() < 23)
							Console::gotoxy(Console::wherex() +6, Console::wherey());
						break;
				}

			}

	if(p_code==0)
		p_code=1;
	else
		p_code = 0;

	}

}